#!/bin/sh
mount -o remount,rw /
# Get Application Install Directory
if (cat /etc/palm/luna.conf | grep -i "/media/cryptofs/apps") ; then
	INSTDIR=/media/cryptofs/apps
else
	INSTDIR=/var
    rm -rf $INSTDIR/usr/palm/applications/com.youjf.justinput/
    rm -f /media/cryptofs/apps/usr/lib/ipkg/info/com.youjf.justinput.control
    rm -f /media/cryptofs/apps/usr/lib/ipkg/info/com.youjf.justinput.list
    rm -f /media/cryptofs/apps/usr/lib/ipkg/info/com.youjf.justinput.pmmanifest
    rm -f /media/cryptofs/apps/usr/lib/ipkg/info/com.youjf.justinput.postinst
    rm -f /media/cryptofs/apps/usr/lib/ipkg/info/com.youjf.justinput.prerm
    exit 0
fi

# install service
mv -f $INSTDIR/usr/palm/applications/com.youjf.justinput/service/justinput.jar /usr/lib/luna/java/
mv -f $INSTDIR/usr/palm/applications/com.youjf.justinput/service/com.youjf.jisrv.service /usr/share/dbus-1/system-services/
mv -f $INSTDIR/usr/palm/applications/com.youjf.justinput/service/com.youjf.com.justinput /etc/event.d/

# core hacks
DBPATH=/var/home/root/.justinput/
mkdir -p $DBPATH
mv -f $INSTDIR/usr/palm/applications/com.youjf.justinput/justinput/db/ $DBPATH
mv -f $INSTDIR/usr/palm/applications/com.youjf.justinput/justinput/ /usr/palm/frameworks/mojo/

HackFile="/usr/palm/frameworks/mojo/mojo.js"
StartLine=`sed -n "/justinput hack start/=" ${HackFile}`
EndLine=`sed -n "/justinput hack end/=" ${HackFile}`
if ((test ${StartLine} > 0) && (test ${EndLine} > 0)) then
    sed "${StartLine},${EndLine}d" "${HackFile}" > ${HackFile}.tmp
    mv -f ${HackFile}.tmp ${HackFile}
fi

# hack the mojo.js
cat $INSTDIR/usr/palm/applications/com.youjf.justinput/service/mojo_append.key.js >> ${HackFile}

rm -rf $INSTDIR/usr/palm/applications/com.youjf.justinput/service/

exit 0
